package com.horay.springclouddemo.stream.multiple.consumer.listener;

import com.horay.springclouddemo.stream.multiple.consumer.message.MessageSource;
import com.horay.springclouddemo.stream.multiple.consumer.message.MessageSink;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * 消息监听器
 *
 * @author heyingcheng
 * @date 2020/3/29 16:40
 */
@Slf4j
@Component
public class MessageListener {

    @Value("${server.port}")
    private String serverPort;

    /**
     * 通过 MessageSink.LOG_INPUT 接收消息
     * 然后通过 SendTo 将处理后的消息发送到 MessageProcessor.LOG_FORMAT_OUTPUT
     */
    @StreamListener(MessageSink.LOG_INPUT)
    @SendTo(MessageSource.LOG_FORMAT_OUTPUT)
    public String processLogMessage(String message) {
        log.info("接收到原始消息:[{}], PORT:[{}]", message, serverPort);
        return "「" + message +"」";
    }

}
